<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../../css/public.css" media="all">
  <style>
    body {
      background-color: #ffffff;
    }
  </style>
</head>
<body>
<div class="layui-form layuimini-form" id="receiving-form" lay-filter="receiving-form">

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">用户ID</label>
    <div class="layui-input-block">
      <input type="text" name="partnerId" readonly value="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">用户昵称</label>
    <div class="layui-input-block">
      <input type="text" name="partnerName" readonly value="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">报名时间</label>
    <div class="layui-input-block">
      <input type="text" name="createTime" readonly value="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">订单状态</label>
    <div class="layui-input-block">
      <input type="text" name="orderStatus" readonly value="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label required">收货人姓名</label>
    <div class="layui-input-block">
      <input type="text" name="consigneeName" lay-verify="required" placeholder="请填写收货人姓名" value=""
             class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label required">手机号码</label>
    <div class="layui-input-block">
      <input type="text" name="consigneePhoneNum" lay-verify="required" placeholder="请填写收货人手机号码" value=""
             class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label required">收货地址</label>
    <div class="layui-input-block">
      <input type="text" name="consigneeAddress" lay-verify="required" placeholder="请填写收货地址" value=""
             class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">备注</label>
    <div class="layui-input-block">
      <input type="text" name="orderRemarks" readonly value="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">物流公司</label>
    <div class="layui-input-block">
      <input type="text" name="courierName" readonly value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">物流单号</label>
    <div class="layui-input-block">
      <input type="text" name="courierNumber" readonly value="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="updateBtn">提交</button>
    </div>
  </div>
</div>

<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../js/lay-module/xm-select-master/dist/xm-select.js" charset="utf-8"></script>
<script>
  let id;
  window.onload = function () {
    id = GetQueryString("id");
    if (isNotNull(id)) {
      init(id);
    } else {
      const iframeIndex = parent.layer.getFrameIndex(window.name);
      parent.layer.close(iframeIndex);
    }
  }

  function init(id) {
    $.ajax({
      type: "get",
      url: '/provide/samples/sub/info/' + id,
      dataType: 'json',
      contentType: 'application/x-www-form-urlencoded',
      success: function (req) {
        if (req.code === '200') {
          layui.use(['form'], function () {
            let form = layui.form
            form.val('receiving-form', {
              "partnerId": req.data.partnerId,
              "partnerName": req.data.partnerName,
              "createTime": req.data.createTime,
              "orderStatus": req.data.orderStatus,
              "consigneeName": req.data.consigneeName,
              "consigneePhoneNum": req.data.consigneePhoneNum,
              "consigneeAddress": req.data.consigneeAddress,
              "orderRemarks": req.data.orderRemarks,
              "courierName": req.data.courierName,
              "courierNumber": req.data.courierNumber
            });
          });
        }
      },
      error: function (e) {
        layer.msg(e.msg);
      }
    })
  }

  layui.use(['layer', 'form'], function () {
    var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

    // 监听提交
    form.on('submit(updateBtn)', function (data) {
      // 组装需要提交数据
      const requestData = {
        id: id ?? void 0,
        consigneeName: data.field.consigneeName ?? void 0,
        consigneePhoneNum: data.field.consigneePhoneNum ?? void 0,
        consigneeAddress: data.field.consigneeAddress ?? void 0,
      }
      var index = layer.alert("确定提交吗？", {
        title: '提示'
      }, function () {
        let myMsg = layer.msg("正在提交...", {
          icon: 16,
          time: -1
        })
        $.ajax({
          type: "post",
          url: '/provide/samples/sub/modifyReceivingInfo',
          data: JSON.stringify(requestData),
          dataType: 'json',
          contentType: 'application/json; charset=UTF-8',
          success: function (req) {
            layer.msg(req.msg);
            layer.close(index);
            // 关闭弹出层
            setTimeout(function () {
              layer.close(myMsg);//手动关闭
              let iframeIndex = parent.layer.getFrameIndex(window.name);
              parent.layer.close(iframeIndex);
            }, 1500);
          },
          error: function (e) {
            layer.msg(e.msg);
            layer.close(myMsg);//手动关闭
          }
        })

      });

      return false;
    });

  });

</script>
</body>
</html>